<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
用户信息
<div id="info"></div>
<div><a id="logout" href="#">退出</a> </div>
<script>

        let xhr = new XMLHttpRequest();
        xhr.open("post", "http://localhost:8080/api/user/1");
        let item = localStorage.getItem("token");
        xhr.setRequestHeader("Authorization",'Bearer '+item)
        // xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8")
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                //1.cookies 2.sessionStorge 3localstorge 4数据库
                if (xhr.status === 200) {
                    console.log("返回的响应" + xhr.responseText);
                    document.getElementById("info").innerHTML=xhr.responseText
                } else {
                    console.log("error" + xhr.status, xhr.responseText);
                }
            }
        }
        xhr.send()

        document.getElementById("logout").addEventListener("click",function (ev){
            ev.preventDefault()
            let xhr = new XMLHttpRequest();
            xhr.open("post","http://localhost:8080/api/logout");
            let item = localStorage.getItem("token");
            xhr.setRequestHeader("Authorization",'Bearer '+item)
            // xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8")
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    //1.cookies 2.sessionStorge 3localstorge 4数据库
                    if (xhr.status === 200) {
                        console.log("返回的响应" + xhr.responseText);
                        location.href = "http://"+location.host+"/userlogin.html"
                    } else {
                        console.log("error" + xhr.status, xhr.responseText);
                    }
                }
            }
            xhr.send()
        })
</script>
</body>
</html>